//
//  DetailMovieView.m
//  豆瓣HW
//
//  Created by dllo on 15/11/26.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DetailMovieView.h"

@implementation DetailMovieView

+ (CGFloat)height:(NSString *)str
{
    
    CGRect frame =  [str boundingRectWithSize:CGSizeMake(370 - 60, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName] context:nil];
    return frame.size.height;
}
- (void)layoutSubviews
{
    
    CGFloat f = [[self class] height:self.labelMakerContent.text];
    CGRect frameL = self.labelMakerContent.frame;
    frameL.size.height = f;
    self.labelMakerContent.frame = frameL;
    
    CGFloat f1 = [[self class] height:self.labelPlotContent.text];
    CGRect frameL1 = self.labelPlotContent.frame;
    frameL1.size.height = f1;
    self.labelPlotContent.frame = frameL1;
    
}

- (void)dealloc
{
    [_imageV release];
    [_labelDate release];
    [_labelTime release];
    [_labelStyle release];
    [_labelCountry release];
    [_labelMakerContent release];
    [_labelPlotContent release];
    [_labelRating release];
    [_labelRating_count release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.backgroundColor = [UIColor whiteColor];
    
    self.contentSize = CGSizeMake(0, self.frame.size.height * 2);
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(30, 10, 120, 150)];
    self.imageV.image = [UIImage imageNamed:@"picholder@2x.png"];
    [self addSubview:self.imageV];
    [self.imageV release];
    
    UILabel *labelComment = [[UILabel alloc] initWithFrame:CGRectMake(self.imageV.frame.origin.x + self.imageV.frame.size.width + 20, self.imageV.frame.origin.y, 50, 30)];
    labelComment.text = @"评分:";
    [self addSubview:labelComment];
    [labelComment release];
    
    self.labelRating = [[UILabel alloc] initWithFrame:CGRectMake(self.imageV.frame.origin.x + self.imageV.frame.size.width + 75, self.imageV.frame.origin.y, 45, 30)];
    [self addSubview:self.labelRating];
    [_labelRating release];
    
    self.labelRating_count = [[UILabel alloc] initWithFrame:CGRectMake(self.labelRating.frame.origin.x + self.labelRating.frame.size.width, self.imageV.frame.origin.y, 100, 30)];
    [self addSubview:self.labelRating_count];
    [_labelRating_count release];
    
    
    self.labelDate = [[UILabel alloc] initWithFrame:CGRectMake(labelComment.frame.origin.x, labelComment.frame.origin.y + labelComment.frame.size.height, 100, 30)];
//    self.labelDate.backgroundColor = [UIColor blackColor];
    [self addSubview:self.labelDate];
    [self.labelDate release];
    
    self.labelTime = [[UILabel alloc] initWithFrame:CGRectMake(self.labelDate.frame.origin.x, self.labelDate.frame.origin.y + self.labelDate.frame.size.height, 100, 30)];
//    self.labelTime.backgroundColor = [UIColor redColor];
    [self addSubview:self.labelTime];
    [self.labelTime release];
    
    self.labelStyle = [[UILabel alloc] initWithFrame:CGRectMake(self.labelTime.frame.origin.x, self.labelTime.frame.origin.y + self.labelTime.frame.size.height, 150, 30)];
//    self.labelStyle.backgroundColor = [UIColor blueColor];
    [self addSubview:self.labelStyle];
    [self.labelStyle release];
    
    self.labelCountry = [[UILabel alloc] initWithFrame:CGRectMake(self.labelStyle.frame.origin.x, self.labelStyle.frame.origin.y + self.labelStyle.frame.size.height, 150, 30)];
//    self.labelCountry.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.labelCountry];
    [self.labelCountry release];
    
    UILabel *labelMaker = [[UILabel alloc] initWithFrame:CGRectMake(self.imageV.frame.origin.x, self.imageV.frame.origin.y + self.imageV.frame.size.height + 15, 80, 30)];
    labelMaker.font = [UIFont systemFontOfSize:24.0];
    labelMaker.text = @"制作人";
    [self addSubview:labelMaker];
    [labelMaker release];

    self.labelMakerContent = [[UILabel alloc] init];
    self.labelMakerContent.frame = CGRectMake(labelMaker.frame.origin.x, labelMaker.frame.origin.y + labelMaker.frame.size.height + 10, self.frame.size.width - 60, 0);
    [self addSubview:self.labelMakerContent];
    self.labelMakerContent.numberOfLines = 0;
    [self.labelMakerContent release];
    
    UILabel *labelPlot = [[UILabel alloc] initWithFrame:CGRectMake(self.labelMakerContent.frame.origin.x, self.labelMakerContent.frame.origin.y + self.labelMakerContent.frame.size.height + 100, 150, 30)];
    labelPlot.font = [UIFont systemFontOfSize:24.0];
    labelPlot.text = @"电影情节";
    [self addSubview:labelPlot];
    [labelPlot release];
    
    self.labelPlotContent = [[UILabel alloc] init];
    self.labelPlotContent.frame = CGRectMake(labelPlot.frame.origin.x, labelPlot.frame.origin.y + labelPlot.frame.size.height + 5, self.frame.size.width - 60, 0);
    [self addSubview:self.labelPlotContent];
    self.labelPlotContent.numberOfLines = 0;
    [self.labelPlotContent release];
    
}

@end
